package com.test;

import io.netty.util.concurrent.*;

import java.util.concurrent.atomic.AtomicInteger;

/**
 * @author wufagang
 * @description
 * @date 2022年06月21日 20:39
 */
public class FutureListenerDemo {
    private static final AtomicInteger terminatedChildren = new AtomicInteger();
    private static final Promise<?> terminationFuture = new DefaultPromise(GlobalEventExecutor.INSTANCE);


    public static void main(String[] args) {
        EventExecutor[] children = new EventExecutor[2];
        final FutureListener<Object> terminationListener = new FutureListener<Object>() {
            @Override
            public void operationComplete(Future<Object> future) throws Exception {
                if (terminatedChildren.incrementAndGet() == children.length) {
                    terminationFuture.setSuccess(null);
                }
            }
        };


        for (EventExecutor e: children) {
            e.terminationFuture().addListener(terminationListener);
        }
    }
}
